v8: add setHeapProfileNearHeapLimit - #64676
Conversation
Signed-off-by: ishabi <ilyasshabi94@gmail.com>
| env, | ||
| }); | ||
| console.log(child.stdout.toString()); | ||
| console.log(child.stderr.toString()); |
There was a problem hiding this comment.
Are the console.log(...) log statements necessary for the test? If not, can we remove them? If they are, can you add a comment?
|
I struggle to see how this API can ever stabilize - what one can do when the heap is near the heap limit is very limited, and in particular if you do too much in the callback to incur another allocation, the program would be in a very unstable state. Our current callbacks only do very limited things within the C++, allowing users to do arbitrary things in JS sounds like an API that invites bugs...I think a safer option would be to only write a profile when it reaches the limit, though even then I am not sure how well the profiler works when the heap is about to reach the limit... |
|
I'm also wary on adding a JS callback to be invoked at new heap limit. This callback also takes a heap profile parameter which is taken on a big heap, sounds like exacerbating the problem it wants to fix. |
|
|
||
| v8.startHeapProfile(); | ||
| v8.setHeapProfileNearHeapLimit((profile) => { | ||
| console.log(JSON.parse(profile)); |
There was a problem hiding this comment.
This example asks users to exacerbating the heap usages when the heap is near limit...
|
This API is not intended to make JS safe near OOM. It closes a blind spot in the sampling heap profiler: today, if a process starts |
|
Why would the application want to save the profile in JS memory when it's likely not relevent for the application itself that may already crash soon? I think a file-backed API would achieve the same thing without making the users waste the remaining memory with (arguably very noisy) diagnostic data. |
|
@joyeecheung Yes I agree with your proposal! I changed the approach to a file-backed one. please feel free to review it |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #64676 +/- ##
==========================================
+ Coverage 90.13% 90.14% +0.01%
==========================================
Files 741 744 +3
Lines 242106 242641 +535
Branches 45551 45709 +158
==========================================
+ Hits 218211 218728 +517
+ Misses 15430 15411 -19
- Partials 8465 8502 +37
🚀 New features to boost your workflow:
|
This PR adds the
v8.setHeapProfileNearHeapLimit(limit)API, which writes the active sampling heap profile to disk when V8 approaches the heap limit. It complementsv8.setHeapSnapshotNearHeapLimit()use cases that need a sampled allocation profile rather than a full heap snapshot.Heap profiling must first be enabled using
v8.startHeapProfile()or the--heap-profCLI option.v8.setHeapProfileNearHeapLimit()andv8.setHeapSnapshotNearHeapLimit()can be active on the same isolate.